/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Affichage;

import Metier.Dialogue;
import Metier.Lieu;
import Metier.News;
import Metier.POI;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author Lâm
 */
public class Ajouter extends JFrame {

    private JButton Submit = null;
    private final JTextField Libelle;
    private final JTextArea Lien;
    private final JTextArea Description;
    private final JLabel lbl_Description;
    private final JLabel lbl_Libelle;
    private final JLabel lbl_Lien;
    private final JScrollPane Panel_Description;
    private final JScrollPane Panel_LienHypertexte;
    private final JPanel Panel_Image;
    private final JButton Parcourir;
    private News news;
    private Dialogue dialogue;

    public Ajouter() throws IOException {
        lbl_Description = new javax.swing.JLabel();
        lbl_Libelle = new javax.swing.JLabel();
        Libelle = new javax.swing.JTextField();
        Panel_LienHypertexte = new javax.swing.JScrollPane();
        Lien = new javax.swing.JTextArea();
        lbl_Lien = new javax.swing.JLabel();
        Panel_Description = new javax.swing.JScrollPane();
        Description = new javax.swing.JTextArea();
        Panel_Image = new JPanel();
        Submit = new JButton();
        Parcourir = new JButton();
        news = new News();
        dialogue = new Dialogue();
    }

    public void AddPOI(final POI poi) {

        Submit.setText("Ajouter");
        Parcourir.setText("Parcourir");
        lbl_Description.setText("Description");

        lbl_Libelle.setText("Libellé");

        Libelle.setText("(Exemple : Musée de Londres)");
        Libelle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            }
        });

        Lien.setColumns(20);
        Lien.setRows(5);
        Panel_LienHypertexte.setViewportView(Lien);

        lbl_Lien.setText("Lien Hypertexte");

        Description.setColumns(20);
        Description.setLineWrap(true);
        Description.setRows(5);
        Panel_Description.setViewportView(Description);
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(Panel_Image);
        Panel_Image.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(lbl_Lien)
                                        .addGap(18, 18, 18))
                                .addGroup(layout.createSequentialGroup()
                                        .addGap(20, 20, 20)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lbl_Libelle)
                                                .addComponent(lbl_Description))
                                        .addGap(42, 42, 42)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(Libelle)
                                .addComponent(Panel_Description, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                                .addComponent(Panel_LienHypertexte))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(Submit, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(Panel_Image, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(Parcourir, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(59, 59, 59))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(Libelle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lbl_Libelle))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lbl_Description)
                                                .addComponent(Panel_Description, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(Panel_LienHypertexte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lbl_Lien)))
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(Panel_Image, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(Parcourir)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                        .addComponent(Submit)
                        .addGap(72, 72, 72))
        );
        Submit.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                Lieu lieu = Affichage.getLieu();
                poi.setLibelle(Libelle.getText());

                poi.setTexte(Description.getText());

                String[] Liens = Lien.getText().split("\n");
                for (String Lien1 : Liens) {
                    poi.addLien(Lien1);
                }
                dialogue.insertPOI(poi);
                dialogue.addPOI(poi, lieu);
                dialogue.WriteIntoNewsFile(poi);
                poi.setVisible(true);
                dispose();
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }
        });
        this.setSize(600, 350);
        this.setVisible(true);
    }
}
